2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
9 namespace SuperPolarity
16 protected Texture2D Texture;
17 protected Vector2 Origin;
20 // Physical Properties
21 public Vector2 Position;
22 protected Vector2 Velocity;
23 protected Vector2 Acceleration;
24 protected float Angle;
26 // Constraints / Behavior
27 protected float MaxVelocity;
28 protected float AccelerationRate;
32 get { return Texture.Width; }
37 get { return Texture.Height; }
40 public Actor(Game newGame)
45 public virtual void Initialize(Texture2D texture, Vector2 position)
51 Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
52 Velocity = new Vector2(0, 0);
53 Acceleration = new Vector2(0, 0);
56 AccelerationRate = 10;
59 public void AutoDeccelerate(GameTime gameTime)
61 if (Acceleration.X == 0 && Velocity.X > 0)
63 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.X)
70 Acceleration.X = -AccelerationRate;
74 if (Acceleration.X == 0 && Velocity.X < 0)
76 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.X)
83 Acceleration.X = AccelerationRate;
87 if (Acceleration.Y == 0 && Velocity.Y > 0)
89 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.Y)
96 Acceleration.Y = -AccelerationRate;
100 if (Acceleration.Y == 0 && Velocity.Y < 0)
102 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.Y)
109 Acceleration.Y = AccelerationRate;
114 public virtual void Update(GameTime gameTime)
120 public void Move(GameTime gameTime)
122 AutoDeccelerate(gameTime);
124 Velocity.X = Velocity.X + Acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
125 Velocity.Y = Velocity.Y + Acceleration.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
127 if (Velocity.X > MaxVelocity)
129 Velocity.X = MaxVelocity;
132 if (Velocity.X < -MaxVelocity)
134 Velocity.X = -MaxVelocity;
137 if (Velocity.Y > MaxVelocity)
139 Velocity.Y = MaxVelocity;
142 if (Velocity.Y < -MaxVelocity)
144 Velocity.Y = -MaxVelocity;
147 Position.X = Position.X + Velocity.X;
148 Position.Y = Position.Y + Velocity.Y;
151 public void ChangeAngle()
153 Angle = (float)Math.Atan2(Velocity.Y, Velocity.X);
156 public virtual void Draw(SpriteBatch spriteBatch)
158 spriteBatch.Draw(Texture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f);